package com.woniuxy.microstockserver.mapper;
import com.woniuxy.microstockserver.bean.AllocationBean;
import com.woniuxy.microstockserver.bean.EnterStockBean;
import com.woniuxy.microstockserver.bean.PageRequestBean;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface AllocationMapper {
    /**
     * 分页、分类、模糊查询所有调拨单
     * @param pageRequestBean
     * @param pageRequestBean,allocationBean
     * @return  PageInfo<AllocationBean>
     */
    List<AllocationBean> findAllAllcationBean(@Param("p") PageRequestBean pageRequestBean, @Param("allo") AllocationBean allocationBean);

    /**
     * 新增调拨单
     * @param allocationBean
     * @return
     */
    @Insert("insert into t_allocation_info (allo_num,fk_allo_enterstore_id,fk_allo_outstore_id,esos_type,esos_amount,allo_handle,allo_makelist_person,allo_makelist_date,allo_audit_status,delete_status,es_remarks) values(#{allo.alloNum},#{allo.alloEnterStoreId},#{allo.alloOutStoreId},#{allo.esosType},#{allo.esosAmount},#{allo.alloHandle},#{allo.alloMakeListPerson},#{allo.alloMakeListDate},#{allo.alloAuditStatus},#{allo.deleteStatus},#{allo.esRemarks})")
    @Options(useGeneratedKeys = true, keyProperty = "allo.id" ,keyColumn="id")
    Long saveAllocationBean(@Param("allo") AllocationBean allocationBean);

    /**
     * 根据id查询调拨单的详情
     * @param id
     * @return
     */
    @Results({
            @Result(id=true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "alloNum",column = "allo_num",javaType = String.class),
            @Result(property = "alloEnterStoreId",column = "fk_allo_enterstore_id",javaType = Long.class),
            @Result(property = "alloOutStoreId",column = "fk_allo_outstore_id",javaType = Long.class),
            @Result(property = "esosType",column = "esos_type",javaType = Integer.class),
            @Result(property = "esosAmount",column = "esos_amount",javaType = Integer.class),
            @Result(property = "alloHandle",column = "allo_handle",javaType = String.class),
            @Result(property = "alloMakeListPerson",column = "allo_makelist_person",javaType = String.class),
            @Result(property = "alloMakeListDate",column = "allo_makelist_date",javaType = Date.class),
            @Result(property = "alloAuditStatus",column = "allo_audit_status",javaType = Integer.class),
            @Result(property = "deleteStatus",column = "delete_status",javaType = Byte.class),
            @Result(property = "esRemarks",column = "es_remarks",javaType = String.class)
    })
    @Select("select * from t_allocation_info where id = #{id}")
    AllocationBean findAllocationAndGoodsDetail(@Param("id") Long id);

    /**
     * 修改调拨单
     * @param allocationBean
     * @return
     */
    @Update("<script>" +
            "update t_allocation_info" +
            "<set>" +
            "<if test='allo.alloNum != null'>" +
            " allo_num = #{allo.alloNum}," +
            "</if>" +
            "<if test='allo.alloEnterStoreId != null'>" +
            " fk_allo_enterstore_id = #{allo.alloEnterStoreId}," +
            "</if>" +
            "<if test='allo.alloOutStoreId != null'>" +
            " fk_allo_outstore_id = #{allo.alloOutStoreId}," +
            "</if>" +
            "<if test='allo.esosType != null'>" +
            " esos_type = #{allo.esosType}," +
            "</if>" +
            "<if test='allo.esosAmount != null'>" +
            " esos_amount = #{allo.esosAmount}," +
            "</if>" +
            "<if test='allo.alloHandle != null'>" +
            " allo_handle = #{allo.alloHandle}," +
            "</if>" +
            "<if test='allo.alloMakeListPerson != null'>" +
            " allo_makelist_person = #{allo.alloMakeListPerson}," +
            "</if>" +
            "<if test='allo.alloMakeListDate != null'>" +
            " allo_makelist_date = #{allo.alloMakeListDate}," +
            "</if>" +
            "<if test='allo.alloAuditStatus != null'>" +
            " allo_audit_status = #{allo.alloAuditStatus}," +
            "</if>" +
            "<if test='allo.deleteStatus != null'>" +
            " delete_status = #{allo.deleteStatus}," +
            "</if>" +
            "<if test='allo.esRemarks != null'>" +
            " es_remarks = #{allo.esRemarks}," +
            "</if>" +
            "</set>" +
            "where id = #{allo.id}" +
            "</script>")
    Long upadteAllocationBean(@Param("allo") AllocationBean allocationBean);


}
